package 牛客_面试必刷.Month07.day12;

import java.util.HashMap;

public class 两数之和 {

    public int[] twoSum (int[] numbers, int target) {
        // write code here
        HashMap<Integer,Integer> map = new HashMap<>();
        map.put(numbers[0],0);
        for (int i = 1; i < numbers.length; i++) {
            int key = numbers[i];
            if(map.containsKey(target - key)){
                return new int[]{map.get(target - key) + 1,i + 1};
            }else{
                map.put(numbers[i],i);
            }
        }
        return null;
    }
}
